<?php

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 * Description of Controller
 *
 * @author mateusz.ledzewicz
 */
abstract class Controller {
    //put your code here
    
    protected $view;
    protected $beginTransaction = false;
    protected $permission = false;
    protected abstract function begin();
    protected abstract function run();
    protected function end(){}
    
    
    public function control(){
        try{
            if(!$this->checkPermission()){
                throw new FatalErrorAccess();
            }
            $this->begin();
            $this->run();
             $this->end();
        } catch(ValidError $validError){
            $this->view->showValidError($validError);
            
        }
    }
    
  
    
    public function getView(){
        if(is_null($this->view))
            throw new SystemError(12);
        
        return $this->view;
    }
    
    public function setView($view){
        if(!is_null($this->view))
            throw new SystemError(13);
        
        $this->view = $view;
    }
    
    private function checkPermission(){
        return true;     
    }
}

?>
